package com.tarena.lbs.activity.dao.repository.impl;

import com.alibaba.cloud.commons.lang.StringUtils;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tarena.lbs.activity.dao.mapper.ActivityMapper;
import com.tarena.lbs.activity.dao.repository.ActivityRepository;
import com.tarena.lbs.activity.pojo.param.ActivityAddParam;
import com.tarena.lbs.activity.pojo.po.ActivityPO;
import com.tarena.lbs.activity.pojo.vo.ActivityVO;
import com.tarena.lbs.base.protocol.pager.PageResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Repository
public class ActivityRepositoryImpl implements ActivityRepository {

    @Autowired
    private ActivityMapper activityMapper;
    @Override
    public void save(ActivityPO activityPO) {
        activityMapper.insert(activityPO);

    }

    @Override
    public PageInfo<ActivityPO> pagesList(ActivityAddParam param) {
        QueryWrapper<ActivityPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("enable_status",0).or().eq("enable_status",1);
        if(param.getStoreName()!=null&& !param.getStoreName().equals("")){
            queryWrapper.eq("activity_name",param.getStoreName());
        }

        //PageHelper.startPage 之间不能有代码
        PageHelper.startPage(1, 10);
        List<ActivityPO> pos = activityMapper.selectList(queryWrapper);
        //selectList 数据库操作 之间不能有代码
        return new PageInfo<>(pos);
    }

    @Override
    public void updateActivityStatus(ActivityAddParam activityAddParam) {
        activityMapper.updateActivityStatus(activityAddParam);
    }

    @Override
    public ActivityPO detail(Integer id) {
        return activityMapper.selectById(id);
    }

    @Override
    public void deleteActivity(ActivityAddParam activityAddParam) {
        activityMapper.deleteActivity(activityAddParam);
    }


    @Override
    public Integer getArticleStatusList(int i) {
        return activityMapper.getArticleStatusList(i);
    }
}
